<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/10/15 13:43
 */

namespace module\ai\library\channel\chat;

use module\ai\library\channel\abstract\Chat;
use OpenAI\Responses\Chat\CreateResponse;
use OpenAI\Responses\StreamResponse;

class GptChat extends Chat
{
    protected string $baseUrl = 'https://api.openai.com/v1';

    public function create(string $prompt, array $options = []): CreateResponse
    {
        if (isset($options['base_url'])) {
            $this->baseUrl = $options['base_url'] ? rtrim($options['base_url'], '/') : $this->baseUrl;
            unset($options['base_url']);
        }

        return parent::create($prompt, $options);
    }

    public function createStreamed(string $prompt, array $options = []): StreamResponse
    {
        if (isset($options['base_url'])) {
            $this->baseUrl = $options['base_url'] ? rtrim($options['base_url'], '/') : $this->baseUrl;
            unset($options['base_url']);
        }

        return parent::createStreamed($prompt, $options);
    }

}